#include "file.h"
#include <stdlib.h>

File* file_open(const char* fileName, const char* mode)
{
  FILE* fp = fopen(fileName, mode);
  if(!fp)
    return NULL;
  File* ret = (File*) malloc(sizeof(File));
  ret->fp = fp;
  ret->line = 0;
  ret->col = 0;
  return ret;
}


inline char file_getc(File* file)
{
  char ret = fgetc(file->fp);
  file->col++;
  if(ret == '\n')
    {
      file->line++;
      file->col = 0;
    }
  return ret;
}


inline char file_isEnd(File* file)
{
  return feof(file->fp);
}


inline void file_readToEndOfLine(File* file)
{
  while(!file_isEnd(file))
    {
      if(file_getc(file) == '\n')
        return;
    }
}
inline char file_skipSpace(File* file)
{
  char c = file_getc(file);
  while(!file_isEnd(file))
    {
      if(c != '\t' && c != ' ')
        return c;
      c = file_getc(file);
    }
}
